var authorityList = {
};

$(function(){
	changeActiveItem('authorityList');
	initTable();
	savehandle();
});
/**
 * 提示信息处理
 */
function savehandle(){
	$('#alertdiv').hide();
	$('#alertdiv').savehandle({
		fieldMap:{},
		successMsg: '删除成功！',
		failMsg: '删除失败，请重试！',
		success: successCallBack
	});
}
function successCallBack(){
	refresh();
}

/**
 * 获取数据
 */
function initTable(){
	$('#grid').grid({
		title:false,
		pager:true,
		checkbox:true,
		multiSelect:true,
		tbar:'#navbar',
		store:{
			url:'/fw/auth/authority_findAll.action',
			idProperty:'authority'
		},
		pageCfg:{
			btnCount:5
		},
		columns:[
			{cn:'编号',en:'authority',width:100,hidden:true},
			{cn:'权限',en:'authority',width:200},
		]
	}) ;
}

/**
 * 刷新
 */
function refresh(){
	$('#grid').grid('load',{data:{}});
}

/**
 * 判定单条删除或批量删除
 * @return {TypeName} 
 */
function del(){
	var ids = $('#grid').grid('getSelectedIds');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要删除的数据!',timer:2000});
		return;
	}else{
		var id = ids.join(",");
	}
	if(confirm("确定要删除这些数据吗？")){
		if(confirm("请再次确认，删除数据后不能恢复！")){
		$.getJSON(
			'/fw/auth/authority_delIds.action',
			{
				'ids':id
			},
			function(data){
				$('#alertdiv').savehandle('handle',data,2000);
			}
		);
	}
}
}
/**
 * 添加权限信息
 * 
 */
function add(){
	window.location.href = "authorityAdd.jsp";
}

/**
 * 设置权限资源
 */
function setResource(){
	var ids = $('#grid').grid('getSelectedIds'),
		id = ids.join(',');
	if(ids.length == 0) {
		$('#alertdiv').savehandle('setmsg',{msg:'请选择要进行资源设置的权限!',timer:2000});
		return;
	}else if(ids.length>1){
		$('#alertdiv').savehandle('setmsg',{msg:'只能选择一条数据进行资源权限设置!',timer:2000});
		return;
	}else{
		location.href = "authResource.jsp#"+id +',admin';
	}
}